<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function fn(){
            var variable,a,b,c,num;
            variable = document.getElementById('ip1');
            variable = Number(variable.value);
            a = parseInt(variable/100);
            b = parseInt(variable/10)%10;
            c = parseInt(variable%10);
            num = a*a*a+b*b*b+c*c*c
            if(num == variable){
                alert("这个三位数是水仙花数");
            }else{
                alert("这个三位数不是水仙花数");
            }
        }
    </script>
</head>
<body>
    <p>输入一个三位数，并判断它是否是水仙花数！</p>
    <input type="text" name="" id="ip1">
    <button onclick="fn()">判断</button>
</body>
</html>